﻿<Views:ViewPage
    x:Class="SecureBox.UI.ViewPage.SearchViewPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" xmlns:local="clr-namespace:SecureBox.UI.Infrastructure.LongList" xmlns:Views="clr-namespace:PhoneCore.Framework.Views;assembly=PhoneCore.Framework" xmlns:Command="clr-namespace:PhoneCore.Framework.Views.Command;assembly=PhoneCore.Framework" FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    mc:Ignorable="d" d:DesignHeight="800" d:DesignWidth="480"
    DataContext="{Binding Search, Source={StaticResource Locator}}"
    shell:SystemTray.IsVisible="False">
    <Views:ViewPage.Resources>
        <DataTemplate x:Name="RecordListHeaderTemplate">
        </DataTemplate>
        <DataTemplate x:Name="RecordGroupHeaderTemplate">
            <TextBlock Text="{Binding Key}" FontSize="{StaticResource PhoneFontSizeLarge}"
                                Foreground="{StaticResource PhoneAccentBrush}" Margin="12,28,0,24"/>
        </DataTemplate>
        <DataTemplate x:Name="RecordGroupItemTemplate">
            <Border Background="{StaticResource PhoneAccentBrush}"
                                Width="432" Height="62"
                                Margin="6" Padding="12,0,0,6">
                <TextBlock Text="{Binding Key}" 
                                    Foreground="#FFFFFF" FontSize="26.667"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Bottom"
                                    FontFamily="{StaticResource PhoneFontFamilySemiBold}"/>
            </Border>
        </DataTemplate>
        <DataTemplate x:Name="RecordItemTemplate">
            <Grid Margin="{StaticResource PhoneTouchTargetOverhang}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Image Width="110" Height="150" Source="{Binding Template.ImageUrl}" VerticalAlignment="Top"/>
                <StackPanel Grid.Column="1" VerticalAlignment="Top">
                    <TextBlock Text="{Binding Name}" Style="{StaticResource PhoneTextLargeStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" TextWrapping="Wrap" Margin="12,-12,12,6"/>
                    <TextBlock Text="{Binding CreationDate}" Style="{StaticResource PhoneTextSmallStyle}" FontFamily="{StaticResource PhoneFontFamilySemiBold}"/>
                    <TextBlock Text="{Binding Description}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" FontFamily="{StaticResource PhoneFontFamilySemiLight}"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </Views:ViewPage.Resources>
    <Grid x:Name="LayoutRoot">
        <StackPanel x:Name="TitlePanel" Margin="12,0,0,0" Canvas.ZIndex="2">
            <TextBlock x:Name="ApplicationTitle" Text="SECURE BOX SEARCH" Style="{StaticResource PhoneTextNormalStyle}"/>
            <toolkit:PhoneTextBox Hint="search query"
                                    Text="{Binding Query, Mode=TwoWay}"  
                                    ActionIcon="/Resources/Images/Actions/Search.png"
                                    InputScope="Text">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="ActionIconTapped">
                        <Command:ExecuteCommandAction Command="{Binding SearchActionIconTappedCommand}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </toolkit:PhoneTextBox>
        </StackPanel>
        <Grid x:Name="ContentPanel"  Margin="0,0,0,0" Canvas.ZIndex="1">
            <toolkit:LockablePivot>
                <toolkit:LockablePivot.Background>
                    <ImageBrush ImageSource="/Resources/Images/LibraryBackground.jpg"/>
                </toolkit:LockablePivot.Background>
                <controls:PivotItem HorizontalAlignment="Stretch">
                    <controls:PivotItem.Header>
                        <TextBlock Margin="0,60,0,0" Text="by name" />
                    </controls:PivotItem.Header>
                    <toolkit:LongListSelector x:Name="RecordsByNameList" ItemsSource="{Binding RecordsByName}"
                                              ListHeaderTemplate="{StaticResource RecordListHeaderTemplate}"
                                              GroupHeaderTemplate="{StaticResource RecordGroupHeaderTemplate}"
                                              GroupItemTemplate="{StaticResource RecordGroupItemTemplate}"
                                              ItemTemplate="{StaticResource RecordItemTemplate}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <Command:ExecuteCommandAction Command="{Binding GoTo}"
                                                CommandParameter="{Binding ElementName=RecordsByNameList}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </toolkit:LongListSelector>
                </controls:PivotItem>
                <controls:PivotItem HorizontalAlignment="Stretch">
                    <controls:PivotItem.Header>
                        <TextBlock Margin="0,60,0,0" Text="by template" />
                    </controls:PivotItem.Header>
                    <toolkit:LongListSelector x:Name="RecordsByTemplatesList" ItemsSource="{Binding RecordsByTemplate}"
                                              ListHeaderTemplate="{StaticResource RecordListHeaderTemplate}"
                                              GroupHeaderTemplate="{StaticResource RecordGroupHeaderTemplate}"
                                              GroupItemTemplate="{StaticResource RecordGroupItemTemplate}"
                                              ItemTemplate="{StaticResource RecordItemTemplate}" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <Command:ExecuteCommandAction Command="{Binding GoTo}"
                                                CommandParameter="{Binding ElementName=RecordsByTemplatesList}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </toolkit:LongListSelector>
                </controls:PivotItem>
                <controls:PivotItem HorizontalAlignment="Stretch">
                    <controls:PivotItem.Header>
                        <TextBlock Margin="0,60,0,0" Text="by keyword" />
                    </controls:PivotItem.Header>
                    <toolkit:LongListSelector x:Name="RecordsByKeywordsList" ItemsSource="{Binding RecordsByKeyword}"
                                              ListHeaderTemplate="{StaticResource RecordListHeaderTemplate}"
                                              GroupHeaderTemplate="{StaticResource RecordGroupHeaderTemplate}"
                                              GroupItemTemplate="{StaticResource RecordGroupItemTemplate}"
                                              ItemTemplate="{StaticResource RecordItemTemplate}" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <Command:ExecuteCommandAction Command="{Binding GoTo}"
                                                CommandParameter="{Binding ElementName=RecordsByKeywordsList}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </toolkit:LongListSelector>
                </controls:PivotItem>
                <controls:PivotItem HorizontalAlignment="Stretch">
                    <controls:PivotItem.Header>
                        <TextBlock Margin="0,60,0,0" Text="by date" />
                    </controls:PivotItem.Header>
                    <toolkit:LongListSelector x:Name="RecordsByDatesList" ItemsSource="{Binding RecordsByDate}"
                                              ListHeaderTemplate="{StaticResource RecordListHeaderTemplate}"
                                              GroupHeaderTemplate="{StaticResource RecordGroupHeaderTemplate}"
                                              GroupItemTemplate="{StaticResource RecordGroupItemTemplate}"
                                              ItemTemplate="{StaticResource RecordItemTemplate}" >
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <Command:ExecuteCommandAction Command="{Binding GoTo}"
                                                CommandParameter="{Binding ElementName=RecordsByDatesList}" />
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </toolkit:LongListSelector>
                </controls:PivotItem>
            </toolkit:LockablePivot>
        </Grid>
    </Grid>
</Views:ViewPage>
